home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * *
- * Smaller Installerâ„¢ *
- * *
- * © 1992 Bill Goodman *
- * All Rights Reserved *
- * *
- *******************************************************************************
-
- Demonstration Hook Example
-
- This is an example of an installer hook procedure. It displays an alert each
- time the hook procedure is called.
-
- To use this hook procedure, you must compile this code and create a code
- resource with type 'SICR' and an ID of 500. This resource should be
- non-preloaded, nonpurgeable, unlocked, unprotected and non-sysheap. Copy this
- resource and the ALRT/DITL resources from the "DemoHook.ALRT.rsrc" file to your
- installer's resource file.
-
- ******************************************************************************/
-
- #include <SetUpA4.h>
- #include "SIHookProc.h"
-
-
- /******************************************************************************
- Module Internal Function Prototypes
- ******************************************************************************/
- void SetTargetVolFunction(void);
- void BeginInstallFunction(void);
- void EndInstallFunction(void);
- void BuildGroupString(unsigned char *groupPStr);
-
-
- /******************************************************************************
- Constant Declarations
- ******************************************************************************/
- /* Alert Definitions */
- #define setTgtAlrt 500 /* Resource ID of SetTargetVol alert */
- #define beginAlrt 501 /* Resource ID of BeginInstall alert */
- #define cancel_beginAlrt 2 /* Item number of CANCEL button */
- #define endAlrt 502 /* Resource ID of EndInstall alert */
- #define cancel_endAlrt 2 /* Item number of CANCEL button */
-
-
- /******************************************************************************
- Module Variables Declarations
- ******************************************************************************/
- SIHookParmBlk *parms; /* Global pointer to parameter block */
- unsigned char emptyPStr[] = "\p"; /* Empty Pascal string */
-
-
- /*****************************************************************************/
- pascal void main(
- SIHookParmBlk *parmBlk /* Pointer to parameter block */
- )
- /******************************************************************************
- This is the main entry point for the installer hook procedure.
- ******************************************************************************/
- {
- RememberA0(); /* This is necessary to access any global variables */
- SetUpA4();
- parms = parmBlk;
-
- switch (parms->function)
- {
- case siHookSetTargetVol:
- SetTargetVolFunction();
- break;
-
- case siHookBeginInstall:
- BeginInstallFunction();
- break;
-
- case siHookEndInstall:
- EndInstallFunction();
- break;
- }
- RestoreA4();
- }
-
-
- /*****************************************************************************/
- void SetTargetVolFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" - Volume reference number of target volume
- "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
- for installation
- Returns:
- "groupAPFlags", "groupQUSel", "groupVZSel" - New installation groups
-
- This function is called at startup and whenever the target volume is
- changed.
- ******************************************************************************/
- {
- HParamBlockRec pb;
- Str255 volumePStr;
- Str255 selectedGroupsPStr;
- OSErr error;
-
- BuildGroupString(selectedGroupsPStr);
-
- /* Get volume name */
- pb.volumeParam.ioVRefNum = parms->targetVRefNum;
- pb.volumeParam.ioNamePtr = volumePStr;
- pb.volumeParam.ioVolIndex = 0;
- error = PBHGetVInfoSync(&pb);
- if (error == noErr)
- { /* Display the target volume name and the selected groups in an alert */
- ParamText(volumePStr, selectedGroupsPStr, emptyPStr, emptyPStr);
- NoteAlert(setTgtAlrt, NULL);
- }
- }
-
-
- /*****************************************************************************/
- void BeginInstallFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" - Volume reference number of target volume
- "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
- for installation
- Returns:
- "result" - Hook result code
-
- This function is called when the install button is clicked to begin
- installing files.
- ******************************************************************************/
- {
- HParamBlockRec pb;
- Str255 volumePStr;
- Str255 selectedGroupsPStr;
- OSErr error;
-
- BuildGroupString(selectedGroupsPStr);
-
- /* Get volume name */
- pb.volumeParam.ioVRefNum = parms->targetVRefNum;
- pb.volumeParam.ioNamePtr = volumePStr;
- pb.volumeParam.ioVolIndex = 0;
- error = PBHGetVInfoSync(&pb);
- if (error != noErr)
- goto Error;
-
- /* Display the target volume name and the selected groups in an alert */
- ParamText(volumePStr, selectedGroupsPStr, emptyPStr, emptyPStr);
- if (NoteAlert(beginAlrt, NULL) == cancel_beginAlrt)
- goto Error; /* Return error to indicate user cancelled operation */
-
- return; /* Note that it is not necessary to set the result if no error */
-
- /* Error occurred or user cancelled operation */
- Error:
- parms->result = siHookAbort;
- }
-
-
- /*****************************************************************************/
- void EndInstallFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" - Volume reference number of target volume
- "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
- for installation
- "completionSts" - Indicates any errors which occurred during installation
- Returns:
- "result" - Hook result code
-
- This function is called at the end of the installation process.
- ******************************************************************************/
- {
- HParamBlockRec pb;
- Str255 volumePStr;
- Str255 selectedGroupsPStr;
- StringPtr statusPtr;
- OSErr error;
-
- if (parms->completionSts == siHookComplete)
- statusPtr = "\pInstallation complete. All files installed.";
- else if (parms->completionSts == siHookFileSkipped)
- statusPtr = "\pInstallation complete. Some files were skipped.";
- else
- statusPtr = "\pInstallation was aborted.";
-
- BuildGroupString(selectedGroupsPStr);
-
- /* Get volume name */
- pb.volumeParam.ioVRefNum = parms->targetVRefNum;
- pb.volumeParam.ioNamePtr = volumePStr;
- pb.volumeParam.ioVolIndex = 0;
- error = PBHGetVInfoSync(&pb);
- if (error != noErr)
- goto Error;
-
- /* Display the target volume name, the selected groups and the completion */
- /* status in an alert */
- ParamText(volumePStr, selectedGroupsPStr, statusPtr, emptyPStr);
- if (NoteAlert(endAlrt, NULL) == cancel_endAlrt)
- goto Error; /* Return error to indicate user cancelled operation */
-
- return; /* Note that it is not necessary to set the result if no error */
-
- /* Error occurred or user cancelled operation */
- Error:
- parms->result = siHookAbort;
- }
-
-
- /*****************************************************************************/
- void BuildGroupString(
- unsigned char *groupPStr /* Returned group string */
- )
- /******************************************************************************
- Build a list of selected groups and return in the specified string.
- ******************************************************************************/
- {
- short index;
- short count;
-
- index = 1;
- for (count = 0; count < 16; count++)
- {
- if (parms->groupAPFlags & (0x0001 << count))
- { /* Group is selected - add to list */
- groupPStr[index++] = 'A' + count;
- groupPStr[index++] = ',';
- groupPStr[index++] = ' ';
- }
- }
- groupPStr[index++] = 'Q' + parms->groupQUSel;
- groupPStr[index++] = ',';
- groupPStr[index++] = ' ';
- groupPStr[index] = 'V' + parms->groupVZSel;
- groupPStr[0] = index;
- }
-